#include "..\CookHeader.h"

typedef  Array <Array <int>> Graph;
Graph initGraph(int size) {
	Graph G;
	Array <int> tmpAry;
	for (int i = 0; i < size; i++) {
		tmpAry.clear();
		for (int k = 0; k < size; k++)
			tmpAry.push_back(0);
		G.push_back(tmpAry);
	}
	return G;
}

int gSize = 5;
Graph G1;
Array <Array <string>> storeAry = { {"GS25    ", "30"}, {"CU      ", "60"}, {"Seven11 ", "10"}, {"MiniStop", "90"}, {"Emart24 ", "40"} };
int GS25 = 0, CU = 1, Seven11 = 2, MiniStop = 3, Emart24 = 4;

void printGraph(Graph g) { 
	print("        ");
	for (int v = 0; v < len(g); v++)
		print(storeAry[v][0]);
	println("");
	for (int row = 0; row < len(g); row++) {
		print(storeAry[row][0]+" ");
		for (int col = 0; col < len(g[row]); col++) {
			print(g[row][col]);
			print("      ");
		}
		println("");
	}
	println("");
}

int main() {
	G1 = initGraph(gSize);
	G1[GS25][CU] = 1; G1[GS25][Seven11] = 1;
	G1[CU][GS25] = 1; G1[CU][Seven11] = 1; G1[CU][MiniStop] = 1;
	G1[Seven11][GS25] = 1; G1[Seven11][CU] = 1; G1[Seven11][MiniStop] = 1;
	G1[MiniStop][Seven11] = 1; G1[MiniStop][CU] = 1; G1[MiniStop][Emart24] = 1;
	G1[Emart24][MiniStop] = 1;

	println("##  ׷ ##\n");
	printGraph(G1);

	Array <int> stack;
	Array <int> visitedAry; // 湮 

	int current = 0;			//  
	int maxStore = current;		// ִ   ȣ(GS25)
	int maxCount = atoi(storeAry[current][1].c_str()); //  ִ Ϲ 
	stack.push_back(current);
	visitedAry.push_back(current);

	while ( len(stack) != 0) {
		int next = -1;
		for (int vertex = 0; vertex < gSize; vertex++) {
			if (G1[current][vertex] == 1) {
				if (isInArray(visitedAry, vertex)) // 湮  ִ ̸ Ż
				{}
				else { // 湮     
					next = vertex;
					break;
				}
			}
		}
		if (next != -1) { //  湮  ִ 
			current = next;
			stack.push_back(current);
			visitedAry.push_back(current);
			if (atoi(storeAry[current][1].c_str()) > maxCount) {
				maxCount = atoi(storeAry[current][1].c_str());
				maxStore = current;
			}
		}
		else { //  湮   
			current = stack[len(stack) - 1];
			stack.pop_back();
		}
	}
	print("ϹĨ ִ  () -->");
	print(storeAry[maxStore][0] + "(" + storeAry[maxStore][1] + ")");
}